beginoutdoorscript; //For the only outdoor section of this scenario

variables;
short endchoice,message,i_am_south,fake,coins;
string reward;

body;
beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
i_am_south = 0;
break;
beginstate START_STATE;
// Starting state of the section, called every turn the party 
// stands inside this section until you change the state.
break;

beginstate 10;
	i_am_south = 0;
	message = has_special_item(0);
	fake = has_special_item(2);
	reset_dialog();
	add_dialog_str(0,"You gaze back north along the road you have come.",0);
	set_state_continue(12);
break;

beginstate 11;
	i_am_south = 1;
	message = has_special_item(0);
	fake = has_special_item(2);
	reset_dialog();
	add_dialog_str(0,"You gaze south along the road you still have to go.",0);
	set_state_continue(12);
break;

beginstate 12;
	block_entry(1); // no passing
	coins = 1000 + 500 * (5 - what_day_of_scenario());
	reset_dialog();
	add_dialog_choice(0,"Continue playing.");
if (message==0 && fake==0) 
{
	add_dialog_str(1,"You have lost the message you swore to deliver. And the Empire does not treat such oaths lightly.",0);
	add_dialog_str(2,"Your only choice, if you wish to survive, is either to retrieve and deliver it, or to leave and run very, very far indeed.",0);
	add_dialog_str(3,"Do you give up and become a fugitive from the Empire's justice?",0);
	add_dialog_choice(1,"Give up - End Scenario.");
}

if (fake + message > 0)
{
	add_dialog_str(2,"You can hardly wait to ride the remaining few miles south to Lorelei and deliver the Imperial express mail to the mayor.",0);
}

if (fake>0)
{
	add_dialog_str(1,"You have retrieved the message from the lair of the goblins. You feel rather amazed at how easy all this was, and are already counting your reward in your mind's eye.",0);
	add_dialog_str(3,"Still, there is something odd. Why did the goblins steal this message? And why was it placed on their altar? Perhaps these are riddles to which you will never know the answer.",0);
	add_dialog_choice(1,"Ride south");
}

if (message>0)
{
	add_dialog_str(1,"You have retrieved the message that the false priest stole from you. After getting through this alive, you feel doubly obligated to fulfill your task.",0);
	add_dialog_str(3,"Still, you have to admire the cunning of that Kernighan. His plan was complex, yet brilliant. Had you not seen through the set-up, you would now deliver his fake message. But he failed to take into account an adventurer's natural curiosity.",0);
	add_dialog_str(4,"The letter you are bearing may be the most important missive sent down this road since Prazac's peace offer to Avernum. Or it may be trivial. But the important part is that you are delivering it, intact and in time.",0);
	if (i_am_south == 0)
	{
		add_dialog_str(3,"Or of course, you could return north to the city of Moon, where the inn was bursting with unemployed adventurers. Someone would be bound to take this off your hands if you want.",0);
		add_dialog_str(4,"But you would never see a piece of gold, and why the hell would you give up NOW?",0);
		add_dialog_choice(1,"Turn back north - Lose Scenario.");
	} else
	{
		add_dialog_choice(1,"Ride south - Win Scenario");
	}
}

	endchoice = run_dialog(1);
	if (endchoice==1) block_entry(1);
	else 
	{
		if (message + fake == 0) end_scenario(0); // given up
		if (message==0)
		{
			reset_dialog();
			message_dialog("You arrive in Lorelei in the early morning hours, and deliver your message to the mayor in person. A clerk already has your reward counted out when the mayor suddenly calls you back in. His face is completely expressionless.",
					"At his request, you nervously recount the journey down from Blackcrag. You feel about ready to leave out the embarrassing episode with the goblins near Backus, when he asks you, quite directly, if at any time the message left your possession.");
			message_dialog("Faced with that, you can only answer truthfully. He sits, his face at first white with fury, then gradually calming. Eventually, as you get to the part where you recovered the message from the goblin lair, he chuckles grimly.",
					"_Foiled again. And I was so sure I had him this time..._ then he begins to explain.");
			add_dialog_str(0,"_A swindler is causing trouble all over Midori province lately. The rest of Northern Valorim, too. No one is safe from him: ",0);
			add_dialog_str(1,"_Shopkeepers, private persons, even many shrines have been conned. His skill is amazing, because he can make the cheapest disguise completely impregnable - until he's safely away. He is a man of a thousand names.",0);
			add_dialog_str(2,"_I was finally close to getting him, but since he is wanted in Footracer as well, the warrant for his arrest had to be signed by the emperor. That was what you were carrying. What you brought me, however..._ he reads from the parchment.",0);
			add_dialog_str(3,"_Greetings, Mayor Linden. Allow me to congratulate you on your recent anniversary, and wish you many more years of_, his lips curl in amusement, _blissful matrimony. Fond regards, Emperor Prazac II._",2);
			add_dialog_str(4,"After a moment of confusion, he adds: _I'm not married, and I am not on personal terms with his Majesty. He toys with me, that crook! But you are not at fault. Greater minds than you have been drawn in by his tricks._",0);
			add_dialog_str(5,"_I will not be notifying the Emperor of this; your failure will have no repercussions. You understand, of course, that you will not receive a reward under these circumstances._ You think it wise not to argue.",0);
			add_dialog_str(6,"_Oh, before I forget, I wanted to show you a drawing I had my guards make from his description._ He reaches into his desk.",0);
			run_dialog(1);
			small_draw_pic_dialog(202,"And a few things suddenly become clear...");
			end_scenario(1); // no reward, but it counts as a win.
		}
		if ( i_am_south==1) {
			change_coins(coins);
			clear_buffer();
			append_string("You arrive in Lorelei in the early morning hours, and deliver your message to the mayor in person. He quickly has a clerk count out your reward, which is now ");
			append_number(coins);
			append_string(" gold, since you delivered the message ");
			if (what_day_of_scenario()==5) append_string("just in time.");
			else 
			{
				append_number(5 - what_day_of_scenario());
				if (what_day_of_scenario()==4) append_string(" day");
				else append_string(" days");
				append_string(" early.");
			}
			get_buffer_text(reward);
			message_dialog(reward,"But as you prepare to leave, the mayor calls you back in. You begin to fear you're in trouble, but he seems to be in a good mood.");
			add_dialog_str(0,"_I trust your journey went unhindered?_ he asks. You are unsure whether to respond truthfully, but decide that the truth reflects very well on you. So you tell him the whole story.",0);
			add_dialog_str(1,"_That trickster. I knew he would try it._ Then he begins to explain.",0);
			add_dialog_str(2,"_A swindler is causing trouble all over Midori province lately. The rest of Northern Valorim, too. No one is safe from him: ",0);
			add_dialog_str(3,"_Shopkeepers, private persons, even many shrines have been conned. His skill is amazing, because he can make the cheapest disguise completely impregnable - until he's safely away. He is a man of a thousand names.",0);
			add_dialog_str(4,"_I was finally close to getting him, but since he is wanted in Footracer as well, the warrant for his arrest had to be signed by the emperor. That was what you were carrying.",0);
			add_dialog_str(5,"_Now I have it here, and you can be sure that when my guards catch him again, he will not get away._ Then he remembers something. _That fake message you spoke of? Could I see it?_ You take it out, he opens it and reads aloud.",0);
			add_dialog_str(6,"_Greetings, Mayor Linden. Allow me to congratulate you on your recent anniversary, and wish you many more years of blissful matrimony. Fond regards, Emperor Prazac II._ His laughter rings through the entire city hall.",2);
			run_dialog(0);
			end_scenario(1);
		}
		else
		{
			//message_dialog("Idiot.","");
			end_scenario(0);
		}
	} 
break;

beginstate 13;
	message_dialog("You could see a fire burning on the top of this hill, and wondered who might be camping here. It turns out to be a goblin hunting party, evidently returning from the north, rich with the spoils of war (mostly the meat of small animals).",
			"You're still trying to decide whether to leave them alone or crash their party when the decision is taken out of your hands. A branch cracks beneath you. Eager for more carnage, the goblins charge. Almost pitiable.");
	set_out_fight_town_loaded(1027);

break;

beginstate 14;
	message_dialog("You wipe your blades clean and let the looting begin. Among the spoils the goblins were bringing home, you not only find lots of meat, but also a heap of coins and a necklace. You try not to think about what happened to the previous owner.","");
	reward_give(302);
	reward_give(9);
	reward_give(9);
	reward_give(9);
	change_coins(100);
break;

beginstate 15;
	if (get_flag(10,1)==1) end();
	if (has_special_item(2)==0) end();
	message_dialog("You stumble upon something weird here, not easily seen. A soft patch in the grassy ground is showing hoof prints as well as the tracks of a carriage."
			"Almost immediately, you think of the carriage you saw outside the Thirsty Herald in Backus. Kernighan! He's been through here! Perhaps you can catch him. Or perhaps, you should leave well enough alone and hurry with the delivery.");
	set_flag(10,1,1);
	set_flag(0,2,0); // put kerny's carriage back in Backus
	create_horse(1,0,15,9,1); // and his horse, too.
break;